<?php
class lappersediaancontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('lappersediaan_model');
	}
	
	function index(){               
		if (isset($_POST['btnview'])) 
		{
		
            if ((isset($_POST['tglawal']) && isset($_POST['tglakhir'])) && (!empty($_POST['tglawal']) && !empty($_POST['tglakhir'])))
			{
				$this->lappersediaan_model->setTanggalAwal($_POST['tglawal']);
				$this->lappersediaan_model->setTanggalAkhir($_POST['tglakhir']);
				$dataprofile = array(
					'page_title' => 'Laporan > Persediaan Barang',
					'name' => $this->session->userdata('fullname'),
					'masterbrg' => $this->lappersediaan_model->getkodebrg(),
					'dt_stock' => $this->lappersediaan_model->getListtanggal(),
					'tglAkhir' => $_POST['tglakhir'],
					'tglAwal' => $_POST['tglawal']
				);  
            }
			elseif($_POST['kdbrgview'] != "")
			{
				$dataprofile = array(
					'page_title' => 'Laporan > Persediaan Barang',
					'name' => $this->session->userdata('fullname'),
					'masterbrg' => $this->lappersediaan_model->getkodebrg(),
					'dt_stock' => $this->lappersediaan_model->getkdbaranglike($_POST['kdbrgview'])		
				);  
            }
			else 
			{
				$dataprofile = array(
					'page_title' => 'Laporan > Persediaan Barang',
					'name' => $this->session->userdata('fullname'),
					'masterbrg' => $this->lappersediaan_model->getkodebrg(),
					'dt_stock' => $this->lappersediaan_model->getList()		
				);		
			}
        } 
		else 
		{
			$dataprofile = array(
				'page_title' => 'Laporan > Persediaan Barang',
				'name' => $this->session->userdata('fullname'),
				'masterbrg' => $this->lappersediaan_model->getkodebrg(),
				'dt_stock' => $this->lappersediaan_model->getList()		
			);		
		}
		$content = array(
			'content' => 'laporan/lappersediaanbarang'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}
	
	function toExcel()
	{		
		if (isset($_REQUEST['btntoxl'])) 
		{		
            if ((isset($_REQUEST['tglawal']) && isset($_REQUEST['tglakhir'])) 
				&& (!empty($_REQUEST['tglawal']) && !empty($_REQUEST['tglakhir'])))
			{
				$this->lappersediaan_model->setTanggalAwal($_REQUEST['tglawal']);
				$this->lappersediaan_model->setTanggalAkhir($_REQUEST['tglakhir']);
				$dataprofile = array(
					'page_title' => 'Laporan > Persediaan Barang',
					'name' => $this->session->userdata('fullname'),
					'masterbrg' => $this->lappersediaan_model->getkodebrg(),
					'dt_stock' => $this->lappersediaan_model->getListtanggal()
				);  
            }
			else if($_REQUEST['kdbrgview'] != "")
			{
				$dataprofile = array(
					'page_title' => 'Laporan > Persediaan Barang',
					'name' => $this->session->userdata('fullname'),
					'masterbrg' => $this->lappersediaan_model->getkodebrg(),
					'dt_stock' => $this->lappersediaan_model->getkdbaranglike($_POST['kdbrgview'])		
				);  
			}
			else
			{
				$dataprofile = array(
					'page_title' => 'Laporan > Persediaan Barang',
					'name' => $this->session->userdata('fullname'),
					'dt_stock' => $this->lappersediaan_model->getList()	
				); 
			}
        } 
		else 
		{
			$dataprofile = array
			(
				'page_title' => '',
				'name' => '',
				'masterbrg' => '',
				'dt_stock' => $this->lappersediaan_model->getList()
			);			
		}
		$content = array
		(
			'content' => 'laporan/excelpersediaanbarang'
		);

		$this->load->view('laporan/excelpersediaanbarang',$dataprofile);
	}
}